package com.tuomaxu.service.impl;

import com.tuomaxu.annotation.Autowired;
import com.tuomaxu.annotation.Component;
import com.tuomaxu.annotation.Qualifier;
import com.tuomaxu.annotation.Transactional;
import com.tuomaxu.dao.AccountDao;
import com.tuomaxu.pojo.Account;
import com.tuomaxu.service.TransferService;

@Component
public class TransferServletImpl implements TransferService {

    @Autowired
    @Qualifier("accountDao")
    private AccountDao accountDao;

    @Override
    @Transactional
    public void transfer(Integer fromCardId, Integer toCardId, Integer money) throws Exception {
        Account fromAccount = accountDao.queryAccountByCId(fromCardId);
        Account toAccount = accountDao.queryAccountByCId(toCardId);

        fromAccount.setMoney(fromAccount.getMoney()-money);
        toAccount.setMoney(toAccount.getMoney()+money);

        accountDao.updateAccount(fromAccount);
        int a = 1/0;
        accountDao.updateAccount(toAccount);
    }
}
